package com.lanou3g.musicenjoy.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lanou3g.musicenjoy.R;
import com.lanou3g.musicenjoy.entity.PlayMusicEntity;
import com.lanou3g.musicenjoy.entity.Song;
import com.lanou3g.musicenjoy.eventbus.MyEvent;

import java.util.List;

import de.greenrobot.event.EventBus;

/**
 * Created by dllo on 15/11/5.
 */
public class PlayMenuAdapter extends BaseAdapter{
    private List<PlayMusicEntity> datas;
    private Context mContext;
    private int a;

    public PlayMenuAdapter(Context c, List<PlayMusicEntity>  datas){
            mContext=c;
            this.datas = datas;

    }
    @Override
    public int getCount() {
        return datas!=null&&datas.size()>0?datas.size():0;
    }

    @Override
    public Object getItem(int position) {
        return datas!=null&&datas.size()>0?datas.get(position):null;
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public View getView( final int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
      //  final int a=0;
        if (convertView==null){
            convertView= LayoutInflater.from(mContext).inflate(R.layout.fragment_play_item,null);
            holder=new ViewHolder();
            holder.textView= (TextView) convertView.findViewById(R.id.playTextView);
            holder.view= (TextView) convertView.findViewById(R.id.playText);
            holder.num= (TextView) convertView.findViewById(R.id.num);
            holder.playImageView= (ImageView) convertView.findViewById(R.id.playImageView);

            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        holder.playImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                datas.remove(position);
                notifyDataSetChanged();
            }
        });


        if (datas!=null) {
            holder.textView.setText(datas.get(position).getSongName());
            holder.view.setText(datas.get(position).getSingerName());
            holder.num.setText(position+1+".");
            Log.i("adapter", datas.get(position).getSingerName());
        }
        return convertView;
    }
    private class ViewHolder{

        private TextView textView;
        private TextView view;
        private TextView num;
        private ImageView playImageView;

    }
}

